#include <iostream>
#include <rectpack2D/finders_interface.h>

using namespace rectpack2D;

int main()
{
	constexpr bool allow_flip = true;
	const auto runtime_flipping_mode = flipping_option::ENABLED;

	using spaces_type = rectpack2D::empty_spaces<allow_flip, default_empty_spaces>;

	using rect_type = output_rect_t<spaces_type>;

	auto report_successful = [](rect_type&)
		{
			return callback_result::CONTINUE_PACKING;
		};

	auto report_unsuccessful = [](rect_type&)
		{
			return callback_result::ABORT_PACKING;
		};

	const auto max_side = 1000;

	const auto discard_step = -4;

	std::vector<rect_type> rectangles;
	rectangles.emplace_back(rect_xywh(0, 0, 20, 40));
	rectangles.emplace_back(rect_xywh(0, 0, 120, 40));
	rectangles.emplace_back(rect_xywh(0, 0, 85, 59));
	rectangles.emplace_back(rect_xywh(0, 0, 199, 380));
	rectangles.emplace_back(rect_xywh(0, 0, 85, 875));

	auto report_result = [&rectangles](const rect_wh& result_size)
		{
			std::cout << "Resultant bin:" << result_size.w << " " << result_size.h << std::endl;
			for (const auto& r : rectangles)
			{
				std::cout << r.x << " " << r.y << " " << r.w << " " << r.h << std::endl;
			}
		};
	{
		const auto result_size = find_best_packing<spaces_type>(
			rectangles, make_finder_input(max_side, discard_step, report_successful, report_unsuccessful, runtime_flipping_mode)
		);
		report_result(result_size);
	}

}